package cn.hist.hfp.controller;

import cn.hist.hfp.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class FileController {

    private final StorageService storageService;

    @Autowired
    public FileController(StorageService storageService) {
        this.storageService = storageService;
    }

    @PostMapping
    public String handleFileUpload(@RequestParam("file") MultipartFile file) {
       return storageService.store(file);
    }

    @DeleteMapping("/{name}")
    public int handleFileDelete(@PathVariable("name") String name) {
        storageService.deleteByName(name);
        return 1;
    }

    @DeleteMapping
    public int handleAllFileDelete() {
        storageService.deleteAll();
        return 1;
    }
}
